package com.zryc.shop.pms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zryc.shop.base.Result;
import com.zryc.shop.pms.entity.Brand;
import com.zryc.shop.pms.service.IBrandService;
import com.zryc.shop.pms.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "品牌管理接口列表")
@RequestMapping("/pms/brand")
public class BrandController {

    @Autowired
    private IBrandService brandService;
    @GetMapping("/list")
    @ApiOperation("分页查询品牌列表")
    public Result list(@RequestParam(required = false) @ApiParam(value = "品牌名称关键词") String keyword,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页大小", required = true) Integer pageSize) {
        return Result.ok(brandService.list(keyword, pageNum, pageSize));
    }

    @PostMapping("/create")
    @ApiOperation("创建品牌")
    public Result create(@RequestBody Brand brand){
        return Result.ok(brandService.save(brand));
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除品牌")
    public Result delete(@PathVariable @ApiParam(value = "品牌ID", required = true) Long id){
        return Result.ok(brandService.removeById(id));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("修改品牌")
    public Result detail(@PathVariable @ApiParam(value = "品牌ID", required = true) Long id,
                                 @RequestBody Brand brand){
        return Result.ok(brandService.updateBrand(id, brand));
    }
    @GetMapping("/{id}")
    @ApiOperation("查询详情")
    public Result detail(@PathVariable @ApiParam(value = "品牌ID", required = true) Long id){
        return Result.ok(brandService.getById(id));
    }

    @PostMapping("/update/factoryStatus")
    @ApiOperation("是否为品牌制造商")
    public Result updateFactoryStatus(@RequestParam Long ids, @RequestParam Integer factoryStatus) {
        return Result.ok(brandService.updateFactoryStatus(ids, factoryStatus));
    }

    @PostMapping("/update/showStatus")
    @ApiOperation("更新显示状态")
    public Result updateShowStatus(@RequestParam @ApiParam(value = "品牌ID列表") String ids,
                                   @RequestParam @ApiParam(value = "显示状态") Integer showStatus){
        return Result.ok(brandService.updateShowStatus(ids, showStatus));
    }

}
